{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 13.3 项目实施"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 13.3.1 获取所有Live"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-03T14:15:59.282186Z",
     "start_time": "2018-12-03T14:15:58.124557Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"paging\": {\"is_end\": false, \"next\": \"https://api.zhihu.com/lives/homefeed?limit=10&offset=10\", \"previous\": \"\"}, \"data\": [{\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 12964, \"max\": 500}, \"id\": \"989811253094866944\", \"in_promotion\": false, \"fee\": {\"original_price\": 999, \"amount\": 999, \"unit\": \"RMB\"}, \"review\": {\"count\": 1624, \"status\": \"normal\", \"score\": 4.78, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"topics\": [{\"type\": \"topic\", \"id\": 18012, \"name\": \"医学\"}], \"type\": \"best_answerer\", \"description\": \"优秀回答者\"}], \"name\": \"马虫 医生\", \"url\": \"https://api.zhihu.com/people/7e8ca6a1f697eb8143a2107a4dd64ecf\", \"type\": \"people\", \"member_role\": \"svip\", \"user_type\": \"people\", \"headline\": \"敬业的外科医生 逗比的理想主义者\", \"avatar_url\": \"https://pic3.zhimg.com/v2-928bb40997855bf78aa795e2c725d25c_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"ma-chong-25-78\", \"id\": \"7e8ca6a1f697eb8143a2107a4dd64ecf\", \"badge_icons\": {\"night\": \"\", \"normal\": \"\"}}, \"bio\": \"敬业的外科医生 逗比的理想主义者\", \"description\": \"马虫医生，哈佛医学院博士后，《一本书读懂前列腺》作者。超过 7 万名听众曾参与他的医知乎Live。\\n\\n\"}, \"role\": \"visitor\", \"subject\": \"初次性生活的准备和事后功课\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": true, \"speaker_message_count\": 117, \"tags\": [{\"name\": \"生活方式\", \"short_name\": \"生活方式\", \"created_at\": 1469691129, \"great_num\": 1063, \"score\": 0, \"available_num\": 1066, \"id\": 101, \"live_num\": 1092}], \"live_type\": \"audio\", \"liked_num\": 2618, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1530198779, \"has_audition\": true, \"is_brand\": false, \"starts_at\": 1530190800}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live989811253094866944\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 6808, \"max\": 500}, \"id\": \"812015618365743104\", \"in_promotion\": false, \"fee\": {\"original_price\": 3900, \"amount\": 3900, \"unit\": \"RMB\"}, \"review\": {\"count\": 1374, \"status\": \"normal\", \"score\": 4.79, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"topics\": [{\"type\": \"topic\", \"id\": 18012, \"name\": \"医学\"}, {\"type\": \"topic\", \"id\": 18040, \"name\": \"妇产科学\"}, {\"type\": \"topic\", \"id\": 458, \"name\": \"科普\"}], \"type\": \"best_answerer\", \"description\": \"优秀回答者\"}], \"name\": \"田吉顺\", \"url\": \"https://api.zhihu.com/people/f20cd1769f61602e2d8d9a6f4ad2ae5d\", \"type\": \"people\", \"member_role\": \"svip\", \"user_type\": \"people\", \"headline\": \"丁香医生医学总监\", \"avatar_url\": \"https://pic2.zhimg.com/v2-6b6512ddd0dfdb105678291dc2c48f9d_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"tian-ji-shun\", \"id\": \"f20cd1769f61602e2d8d9a6f4ad2ae5d\", \"badge_icons\": {\"night\": \"\", \"normal\": \"\"}}, \"bio\": \"丁香医生医学总监\", \"description\": \"我是田吉顺，之前在公立三甲医院工作了 10 年，今年走出体制，想要做一些互联网医疗相关的尝试，现在丁香诊所做妇产科医学总监。\"}, \"role\": \"visitor\", \"subject\": \"如何科学度过怀孕前三个月？\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 97, \"tags\": [{\"name\": \"医学与健康\", \"short_name\": \"医学健康\", \"created_at\": 1469691129, \"great_num\": 415, \"score\": 0, \"available_num\": 416, \"id\": 203, \"live_num\": 422}], \"live_type\": \"audio\", \"liked_num\": 5215, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1487947251, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1487941200}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live812015618365743104\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 40529, \"max\": 500}, \"id\": \"870704471959822336\", \"in_promotion\": false, \"fee\": {\"original_price\": 999, \"amount\": 999, \"unit\": \"RMB\"}, \"review\": {\"count\": 5443, \"status\": \"normal\", \"score\": 4.35, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [], \"name\": \"安晓辉\", \"url\": \"https://api.zhihu.com/people/f33e4e299ef5fcc7d792adb333671cfa\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"people\", \"headline\": \"《程序员的成长课》作者，职业规划师，自由职业者\", \"avatar_url\": \"https://pic4.zhimg.com/v2-5e91759e7a52026418297b6b7acd12d7_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"foruok\", \"id\": \"f33e4e299ef5fcc7d792adb333671cfa\", \"badge_icons\": {}}, \"bio\": \"《程序员的成长课》作者，职业规划师，自由职业者\", \"description\": \"安晓辉，自由职业者 / 作家 / 职业规划师 / 知乎 Live 讲者 / 开发者 / 讲师 / 自媒体人 / 值乎答主 / 分答答主 / 在行行家，著有《 Qt Quick 核心编程》《你好哇，程序员》等图书。\"}, \"role\": \"visitor\", \"subject\": \"业余时间赚钱的6种策略\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 111, \"tags\": [{\"name\": \"互联网\", \"short_name\": \"互联网\", \"created_at\": 1469691129, \"great_num\": 1047, \"score\": 0, \"available_num\": 1067, \"id\": 105, \"live_num\": 1085}], \"live_type\": \"audio\", \"liked_num\": 41452, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1502201140, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1502195400}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live870704471959822336\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 19581, \"max\": 500}, \"id\": \"826057084528394240\", \"in_promotion\": false, \"fee\": {\"original_price\": 0, \"amount\": 0, \"unit\": \"RMB\"}, \"review\": {\"count\": 1208, \"status\": \"normal\", \"score\": 4.69, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [{\"member\": {\"is_followed\": false, \"badge\": [], \"name\": \"胡半仙\", \"url\": \"https://api.zhihu.com/people/1cb11bdfbcd94fe75944208497e682c4\", \"type\": \"people\", \"member_role\": \"svip\", \"user_type\": \"people\", \"headline\": \"公众号：胡佳威，儿童性教育老师\", \"avatar_url\": \"https://pic1.zhimg.com/40b326eebb3b2a912f93caf5d243fa23_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"hu-ban-xian\", \"id\": \"1cb11bdfbcd94fe75944208497e682c4\", \"badge_icons\": {\"night\": \"\", \"normal\": \"\"}}, \"bio\": \"公众号：胡佳威，儿童性教育老师\", \"description\": \"我是胡佳威，不羞学堂发起人，也是保护豆豆儿童性教育老师，中国性学会青少年专委会成员，拥有 5 年青少年性教育经历， 3 年儿童性教育创业经历。\", \"index\": 0}], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"type\": \"identity\", \"description\": \"已认证的官方帐号\"}, {\"topics\": [{\"type\": \"topic\", \"id\": 458, \"name\": \"科普\"}], \"type\": \"best_answerer\", \"description\": \"优秀回答者\"}], \"name\": \"中国科普博览\", \"url\": \"https://api.zhihu.com/people/da971e1f564d733611f6a9a51930c4aa\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"organization\", \"headline\": \"我们科学家有话说\", \"avatar_url\": \"https://pic1.zhimg.com/c1b4a75b500a354b1b6dfa2b7ddfefaf_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"zhong-guo-ke-pu-bo-lan\", \"id\": \"da971e1f564d733611f6a9a51930c4aa\", \"badge_icons\": {}}, \"bio\": \"我们科学家有话说\", \"description\": \"不是所有的问题都能用科学解答，但对我来说，能用科学解答的问题都不是问题。\\r\\n说好的 Live ，我来啦！\\r\\n\\r\\n中国科普博览是中科院的网络化科学传播平台。来这里，那些未知世界的探索者为您讲述科学之美。\\r\\n本场 Live 邀请到两位主讲，一位是玛丽斯特普中国项目主管王龙玺，玛丽斯特普中国是国内青少年性教育领域最专业的组织之一；另一位是不羞学堂发起人胡佳威。\"}, \"role\": \"visitor\", \"subject\": \"如何正确跟孩子谈「性」说爱\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 73, \"tags\": [{\"name\": \"心理学\", \"short_name\": \"心理学\", \"created_at\": 1469691129, \"great_num\": 291, \"score\": 0, \"available_num\": 303, \"id\": 202, \"live_num\": 313}], \"live_type\": \"audio\", \"liked_num\": 1564, \"artwork\": \"https://pic2.zhimg.com/v2-1d63d558e071733d4ab123d67881fc13_r.jpg\", \"is_public\": 1, \"ends_at\": 1491488176, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1491480000}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live826057084528394240\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 26141, \"max\": 500}, \"id\": \"860165089880330240\", \"in_promotion\": false, \"fee\": {\"original_price\": 999, \"amount\": 999, \"unit\": \"RMB\"}, \"review\": {\"count\": 2864, \"status\": \"normal\", \"score\": 4.71, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [], \"name\": \"半佛仙人\", \"url\": \"https://api.zhihu.com/people/ec7b66af7cd513fd3659d3c3ee347a77\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"people\", \"headline\": \"我看诸君皆装逼，料诸君看我应如是\", \"avatar_url\": \"https://pic3.zhimg.com/v2-18283ea0c30d6f8d6d9944bf394b6c86_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"banfoxianren\", \"id\": \"ec7b66af7cd513fd3659d3c3ee347a77\", \"badge_icons\": {}}, \"bio\": \"我看诸君皆装逼，料诸君看我应如是\", \"description\": \"我是半佛仙人，曾供职于担保公司、中资银行、外资银行、互联网金融公司。从 payday laon 到金融资产，从 ipc 到大数据风控均有涉猎。我本人持 8 张白金卡，同时在征信（过目 10W 份 +）、信用卡风控及催收领域有着丰富的实战经验，天天与一线黑产相爱相杀。\"}, \"role\": \"visitor\", \"subject\": \"信用卡游戏的潜规则及用卡攻略\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 228, \"tags\": [{\"name\": \"金融与经济\", \"short_name\": \"金融经济\", \"created_at\": 1469691129, \"great_num\": 874, \"score\": 0, \"available_num\": 891, \"id\": 301, \"live_num\": 909}], \"live_type\": \"audio\", \"liked_num\": 12246, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1498836539, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1498824000}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live860165089880330240\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 20115, \"max\": 500}, \"id\": \"835121024906432512\", \"in_promotion\": false, \"fee\": {\"original_price\": 999, \"amount\": 999, \"unit\": \"RMB\"}, \"review\": {\"count\": 3352, \"status\": \"normal\", \"score\": 4.54, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"type\": \"identity\", \"description\": \"凤凰卫视 记者\"}], \"name\": \"潘玥\", \"url\": \"https://api.zhihu.com/people/5554bf8a44eb7848c3274d0675f06f1e\", \"type\": \"people\", \"member_role\": \"svip\", \"user_type\": \"people\", \"headline\": \"凤凰卫视记者/前新东方托福雅思听口教师\", \"avatar_url\": \"https://pic4.zhimg.com/v2-c537d2297c3a597cd18f6c5cf4460d45_s.jpg\", \"is_following\": false, \"gender\": 0, \"url_token\": \"panyue0109\", \"id\": \"5554bf8a44eb7848c3274d0675f06f1e\", \"badge_icons\": {\"night\": \"\", \"normal\": \"\"}}, \"bio\": \"凤凰卫视新生代记者，前新东方托福雅思教师\", \"description\": \"我是潘玥，凤凰卫视记者，前新东方托福雅思听力口语教师，为研究新媒体刚注册账号一个月的知乎小白，首场 Live「85 后记者香港从业体验思考」五星评分主讲，话题「高度自律是种怎样的体验」高赞答主。\"}, \"role\": \"visitor\", \"subject\": \"高度自律：为了高度自由\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 254, \"tags\": [{\"name\": \"生活方式\", \"short_name\": \"生活方式\", \"created_at\": 1469691129, \"great_num\": 1063, \"score\": 0, \"available_num\": 1066, \"id\": 101, \"live_num\": 1092}], \"live_type\": \"audio\", \"liked_num\": 16511, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1492961710, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1492948800}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live835121024906432512\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 91285, \"max\": 500}, \"id\": \"897097999497437184\", \"in_promotion\": false, \"fee\": {\"original_price\": 999, \"amount\": 999, \"unit\": \"RMB\"}, \"review\": {\"count\": 13113, \"status\": \"normal\", \"score\": 4.53, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"type\": \"identity\", \"description\": \"传媒学者、资深媒体人\"}], \"name\": \"五道口奥萨玛\", \"url\": \"https://api.zhihu.com/people/69299bc43e36728a3bb32d96d998944b\", \"type\": \"people\", \"member_role\": \"instabook\", \"user_type\": \"people\", \"headline\": \"通利福尼亚州州立大学\", \"avatar_url\": \"https://pic3.zhimg.com/608a316b5_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"5daokou\", \"id\": \"69299bc43e36728a3bb32d96d998944b\", \"badge_icons\": {}}, \"bio\": \"通利福尼亚州州立大学\", \"description\": \"我是周逵，传媒学者，资深媒体人。清华大学&美国麻省理工学院联合培养博士，麻省理工学院媒体实验室的访问学者。曾译著的《群体性孤独》获 2015 年文津图书奖，多年来我主要研究人际传播、社会化社交、人际交往方面的知识。\"}, \"role\": \"visitor\", \"subject\": \"如何从尬聊到亲密沟通？\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 76, \"tags\": [{\"name\": \"心理学\", \"short_name\": \"心理学\", \"created_at\": 1469691129, \"great_num\": 291, \"score\": 0, \"available_num\": 303, \"id\": 202, \"live_num\": 313}], \"live_type\": \"audio\", \"liked_num\": 71692, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1509372072, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1509364800}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live897097999497437184\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 5127, \"max\": 500}, \"id\": \"850711363683770368\", \"in_promotion\": false, \"fee\": {\"original_price\": 999, \"amount\": 999, \"unit\": \"RMB\"}, \"review\": {\"count\": 1062, \"status\": \"normal\", \"score\": 4.86, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"type\": \"identity\", \"description\": \"北京大学口腔医院 口腔医师\"}, {\"topics\": [{\"type\": \"topic\", \"id\": 12956, \"name\": \"口腔医学\"}, {\"type\": \"topic\", \"id\": 26525, \"name\": \"牙科\"}], \"type\": \"best_answerer\", \"description\": \"优秀回答者\"}], \"name\": \"许桐楷\", \"url\": \"https://api.zhihu.com/people/99540c3229cd7a4d805a2e43c57d9c8f\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"people\", \"headline\": \"牙医\", \"avatar_url\": \"https://pic4.zhimg.com/7e1c36b18_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"xu-tong-kai\", \"id\": \"99540c3229cd7a4d805a2e43c57d9c8f\", \"badge_icons\": {}}, \"bio\": \"牙医\", \"description\": \"牙医。北京大学口腔医学博士。口腔全科医师。\"}, \"role\": \"visitor\", \"subject\": \"根管治疗前你该知道的事\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": true, \"speaker_message_count\": 87, \"tags\": [{\"name\": \"医学与健康\", \"short_name\": \"医学健康\", \"created_at\": 1469691129, \"great_num\": 415, \"score\": 0, \"available_num\": 416, \"id\": 203, \"live_num\": 422}], \"live_type\": \"audio\", \"liked_num\": 1191, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1498831743, \"has_audition\": true, \"is_brand\": false, \"starts_at\": 1498825800}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live850711363683770368\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 4246, \"max\": 1000000}, \"id\": \"1045284726512451584\", \"in_promotion\": false, \"fee\": {\"original_price\": 0, \"amount\": 0, \"unit\": \"RMB\"}, \"review\": {\"count\": 102, \"status\": \"normal\", \"score\": 4.74, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"topics\": [{\"type\": \"topic\", \"id\": 15318, \"name\": \"发展心理学\"}, {\"type\": \"topic\", \"id\": 404, \"name\": \"心理学\"}], \"type\": \"best_answerer\", \"description\": \"优秀回答者\"}], \"name\": \"叶壮\", \"url\": \"https://api.zhihu.com/people/a7a123d45f6505eff7f1dec9bbc03d4b\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"people\", \"headline\": \"心理学培训师\", \"avatar_url\": \"https://pic2.zhimg.com/v2-b2d2e506315b334e935773c639f68eb7_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"yezhuang\", \"id\": \"a7a123d45f6505eff7f1dec9bbc03d4b\", \"badge_icons\": {}}, \"bio\": \"心理学培训师\", \"description\": \"我是叶壮，是一名心理培训师，毕业于中科院心理所发展与教育心理学系；同时，我也是中国心理学会会员、美国心理科学协会（APS）会员；我在亲密关系、亲子关系方面有丰富的研究和培训经验，曾出版《我们：亲密关系的心理必修课》《心理学·必须的》等著作；\"}, \"role\": \"visitor\", \"subject\": \"如何提高表白成功率\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": true, \"speaker_message_count\": 107, \"tags\": [{\"name\": \"心理学\", \"short_name\": \"心理学\", \"created_at\": 1469691129, \"great_num\": 291, \"score\": 0, \"available_num\": 303, \"id\": 202, \"live_num\": 313}], \"live_type\": \"audio\", \"liked_num\": 10, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1542289867, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1542283200}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live1045284726512451584\"}, {\"object_type\": \"live\", \"source_type\": \"member\", \"live\": {\"liked\": false, \"is_commercial\": false, \"video\": {}, \"seats\": {\"taken\": 91220, \"max\": 500}, \"id\": \"927876522726027264\", \"in_promotion\": false, \"fee\": {\"original_price\": 990, \"amount\": 990, \"unit\": \"RMB\"}, \"review\": {\"count\": 243, \"status\": \"normal\", \"score\": 4.56, \"has_reviewed\": false, \"previous\": {\"status\": \"nonexistent\", \"score\": 0}}, \"cospeakers\": [{\"member\": {\"is_followed\": false, \"badge\": [], \"name\": \"胡晓波\", \"url\": \"https://api.zhihu.com/people/b1872e7cc960a0245e745c1cf162ad5b\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"people\", \"headline\": \"各种理性谈论（吐槽）护肤品。公众号：配方师Rex。\", \"avatar_url\": \"https://pic3.zhimg.com/260a51caa7e978390ffa2d7c3a6a98e7_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"hu-xiao-bo-1025\", \"id\": \"b1872e7cc960a0245e745c1cf162ad5b\", \"badge_icons\": {}}, \"bio\": \"各种理性谈论（吐槽）护肤品。公众号：配方师Rex。\", \"description\": \"大家好，我是配方师胡晓波，毕业于复旦大学生物系，是一名护肤品的研发工程师，在世界五百强企业的护肤品研发中心已经工作多年，对护肤品配方涉及的技术特别着迷和感兴趣，也开发过许多护肤品，涉及保湿、防晒、敏感肌、抗衰老各类领域。同时我还在各大平台上发表了许多关于护肤品热点和趋势的技术文章，阅读量超过百万。\", \"index\": 0}], \"speaker\": {\"member\": {\"is_followed\": false, \"badge\": [{\"type\": \"identity\", \"description\": \"已认证的官方帐号\"}], \"name\": \"网易美学\", \"url\": \"https://api.zhihu.com/people/35baa67071a2d63988ebcb7b8d13fce3\", \"type\": \"people\", \"member_role\": \"\", \"user_type\": \"organization\", \"headline\": \"网易首个美妆社区，专注发现适合你的美；APP | 公众号 | 微博：网易美学\", \"avatar_url\": \"https://pic1.zhimg.com/v2-940f8e4b2a1109650067f50c78d2f0a0_s.jpg\", \"is_following\": false, \"gender\": 1, \"url_token\": \"wang-yi-mei-xue-36\", \"id\": \"35baa67071a2d63988ebcb7b8d13fce3\", \"badge_icons\": {}}, \"bio\": \"网易首个美妆社区，专注发现适合你的美；APP | 公众号 | 微博：网易美学\", \"description\": \"「网易美学」，一个专注发现变美技巧与分享心得的美妆社区，充分理解时下年轻人的美妆态度。爱美的你可以发现美妆界最新最热资讯，关注全世界的美学家，还可以与大家分享心水好物，找到适合自己的变美方法。\"}, \"role\": \"visitor\", \"subject\": \"网红时代我们如何理性选择护肤品？\", \"type\": \"live\", \"brand_label\": \"\", \"status\": \"ended\", \"ends_in\": 0, \"is_audition_open\": false, \"speaker_message_count\": 128, \"tags\": [{\"name\": \"生活方式\", \"short_name\": \"生活方式\", \"created_at\": 1469691129, \"great_num\": 1063, \"score\": 0, \"available_num\": 1066, \"id\": 101, \"live_num\": 1092}], \"live_type\": \"audio\", \"liked_num\": 1043, \"artwork\": \"\", \"is_public\": 1, \"ends_at\": 1516026959, \"has_audition\": false, \"is_brand\": false, \"starts_at\": 1516017600}, \"action\": \"recommended_by_algo\", \"source_id\": 0, \"id\": \"live927876522726027264\"}], \"attached_info\": \"MiBjZjQyOTllNWI0NTY0NmUwODVmYWIyMDY5MmFjMDc4Mw==\"}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "\n",
    "def scrapy(link):\n",
    "    headers = {\n",
    "        'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'\n",
    "    } \n",
    "    r = requests.get(link, headers= headers)\n",
    "    return (r.text)\n",
    "\n",
    "link = \"https://api.zhihu.com/lives/homefeed?includes=live\"\n",
    "html = scrapy(link)\n",
    "print (html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-03T14:18:17.244110Z",
     "start_time": "2018-12-03T14:18:17.241101Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=10\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "decodejson = json.loads(html)\n",
    "next_page = decodejson['paging']['next']\n",
    "is_end = decodejson['paging']['is_end']\n",
    "print (next_page)\n",
    "print (is_end)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-03T14:28:13.718225Z",
     "start_time": "2018-12-03T14:27:42.020109Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=10 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=20 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=30 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=40 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=50 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=60 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=70 False\n",
      "https://api.zhihu.com/lives/homefeed?limit=10&offset=80 True\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from pymongo import MongoClient\n",
    "import json\n",
    "import time\n",
    "import random\n",
    "\n",
    "#连接MongoDB\n",
    "client = MongoClient('localhost',27017)\n",
    "db = client.zhihu_database\n",
    "collection = db.live\n",
    "\n",
    "#定义爬虫函数\n",
    "def scrapy(link):\n",
    "    headers = {\n",
    "        'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'\n",
    "    } \n",
    "    r = requests.get(link, headers= headers)\n",
    "    return (r.text)\n",
    "\n",
    "link = \"https://api.zhihu.com/lives/homefeed?includes=live\"\n",
    "is_end = False\n",
    "#循环获取所有Live\n",
    "while not is_end:\n",
    "    html = scrapy(link)\n",
    "    decodejson = json.loads(html)\n",
    "    collection.insert_one(decodejson)\n",
    "    \n",
    "    link = decodejson['paging']['next']\n",
    "    is_end = decodejson['paging']['is_end']\n",
    "    print (link, is_end)\n",
    "    time.sleep(random.randint(2,3) + random.random())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 13.3.2 获取Live的听众"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-03T14:32:25.362459Z",
     "start_time": "2018-12-03T14:32:25.338394Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "989811253094866944\n",
      "812015618365743104\n",
      "870704471959822336\n",
      "826057084528394240\n",
      "860165089880330240\n",
      "835121024906432512\n",
      "897097999497437184\n",
      "850711363683770368\n",
      "1045284726512451584\n",
      "927876522726027264\n"
     ]
    }
   ],
   "source": [
    "from pymongo import MongoClient\n",
    "client = MongoClient('localhost',27017)\n",
    "db = client.zhihu_database\n",
    "collection = db.live\n",
    "\n",
    "first_page = collection.find_one()\n",
    "for each in first_page['data']:\n",
    "    print (each['live']['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-12-03T14:48:49.976282Z",
     "start_time": "2018-12-03T14:33:43.503119Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=10 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=20 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=30 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=40 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=50 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=60 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=70 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=80 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=90 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=100 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=110 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=120 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=130 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=140 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=150 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=160 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=170 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=180 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=190 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=200 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=210 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=220 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=230 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=240 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=250 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=260 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=270 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=280 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=290 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=300 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=310 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=320 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=330 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=340 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=350 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=360 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=370 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=380 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=390 False\n",
      "https://api.zhihu.com/lives/989811253094866944/members?limit=10&offset=400 False\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m    379\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# Python 2.7, use buffering of HTTP responses\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 380\u001b[1;33m                 \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbuffering\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    381\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# Python 2.6 and older, Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: getresponse() got an unexpected keyword argument 'buffering'",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-11-6f322655ca2b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     29\u001b[0m         \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrandom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrandint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mrandom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrandom\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     30\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 31\u001b[1;33m \u001b[0mget_audience\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlive_id\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-11-6f322655ca2b>\u001b[0m in \u001b[0;36mget_audience\u001b[1;34m(live_id)\u001b[0m\n\u001b[0;32m     18\u001b[0m     \u001b[0mis_end\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     19\u001b[0m     \u001b[1;32mwhile\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mis_end\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 20\u001b[1;33m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlink\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mproxies\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mproxies\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     21\u001b[0m         \u001b[0mhtml\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     22\u001b[0m         \u001b[0mdecodejson\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\api.py\u001b[0m in \u001b[0;36mget\u001b[1;34m(url, params, **kwargs)\u001b[0m\n\u001b[0;32m     70\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     71\u001b[0m     \u001b[0mkwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefault\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'allow_redirects'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 72\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'get'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     73\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     74\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\api.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(method, url, **kwargs)\u001b[0m\n\u001b[0;32m     56\u001b[0m     \u001b[1;31m# cases, and look like a memory leak in others.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     57\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0msessions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSession\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0msession\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 58\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0msession\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0murl\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0murl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     59\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     60\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36mrequest\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m    506\u001b[0m         }\n\u001b[0;32m    507\u001b[0m         \u001b[0msend_kwargs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msettings\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 508\u001b[1;33m         \u001b[0mresp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0msend_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    509\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    510\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mresp\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\sessions.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m    616\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    617\u001b[0m         \u001b[1;31m# Send the request\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 618\u001b[1;33m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0madapter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrequest\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    619\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    620\u001b[0m         \u001b[1;31m# Total elapsed time of the request (approximately)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\requests\\adapters.py\u001b[0m in \u001b[0;36msend\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    438\u001b[0m                     \u001b[0mdecode_content\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    439\u001b[0m                     \u001b[0mretries\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax_retries\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 440\u001b[1;33m                     \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    441\u001b[0m                 )\n\u001b[0;32m    442\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36murlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    599\u001b[0m                                                   \u001b[0mtimeout\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtimeout_obj\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    600\u001b[0m                                                   \u001b[0mbody\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbody\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mheaders\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 601\u001b[1;33m                                                   chunked=chunked)\n\u001b[0m\u001b[0;32m    602\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    603\u001b[0m             \u001b[1;31m# If we're going to release the connection in ``finally:``, then\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py\u001b[0m in \u001b[0;36m_make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m    381\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# Python 2.6 and older, Python 3\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    382\u001b[0m                 \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 383\u001b[1;33m                     \u001b[0mhttplib_response\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconn\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetresponse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    384\u001b[0m                 \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    385\u001b[0m                     \u001b[1;31m# Remove the TypeError from the exception chain in Python 3;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mgetresponse\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1329\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1330\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1331\u001b[1;33m                 \u001b[0mresponse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbegin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1332\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mConnectionError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1333\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36mbegin\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    295\u001b[0m         \u001b[1;31m# read until we get a non-100 response\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    296\u001b[0m         \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 297\u001b[1;33m             \u001b[0mversion\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatus\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mreason\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    298\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mstatus\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mCONTINUE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    299\u001b[0m                 \u001b[1;32mbreak\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\http\\client.py\u001b[0m in \u001b[0;36m_read_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    256\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    257\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_read_status\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 258\u001b[1;33m         \u001b[0mline\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreadline\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_MAXLINE\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"iso-8859-1\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    259\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mline\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>\u001b[0m \u001b[0m_MAXLINE\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    260\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mLineTooLong\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"status line\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\socket.py\u001b[0m in \u001b[0;36mreadinto\u001b[1;34m(self, b)\u001b[0m\n\u001b[0;32m    584\u001b[0m         \u001b[1;32mwhile\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    585\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 586\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    587\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    588\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_timeout_occurred\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\urllib3\\contrib\\pyopenssl.py\u001b[0m in \u001b[0;36mrecv_into\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m    278\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    279\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 280\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    281\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mOpenSSL\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSSL\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSysCallError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    282\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msuppress_ragged_eofs\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0margs\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Unexpected EOF'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\OpenSSL\\SSL.py\u001b[0m in \u001b[0;36mrecv_into\u001b[1;34m(self, buffer, nbytes, flags)\u001b[0m\n\u001b[0;32m   1811\u001b[0m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_lib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSSL_peek\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_ssl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnbytes\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1812\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1813\u001b[1;33m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_lib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mSSL_read\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_ssl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbuf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnbytes\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1814\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_raise_ssl_error\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_ssl\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1815\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from pymongo import MongoClient\n",
    "import json\n",
    "import time\n",
    "import random\n",
    "\n",
    "client = MongoClient('localhost',27017)\n",
    "db = client.zhihu_database\n",
    "    \n",
    "live_id = '989811253094866944'\n",
    "\n",
    "def get_audience(live_id):\n",
    "    headers = {\n",
    "        'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'\n",
    "    } \n",
    "    link = 'https://api.zhihu.com/lives/' + live_id + '/members?limit=10&offset=0'\n",
    "    \n",
    "    is_end = False\n",
    "    while not is_end:\n",
    "        r = requests.get(link, headers= headers)\n",
    "        html = r.text\n",
    "        decodejson = json.loads(html)\n",
    "        decodejson['live_id'] = live_id\n",
    "        db.live_audience.insert_one(decodejson)\n",
    "\n",
    "        link = decodejson['paging']['next']\n",
    "        is_end = decodejson['paging']['is_end']\n",
    "        print(link, is_end)\n",
    "        time.sleep(random.randint(2,3) + random.random())\n",
    "\n",
    "get_audience(live_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "840520148518592512\n",
      "837669764146003968\n",
      "837693085466107904\n",
      "843124614065434624\n",
      "842731562154987520\n",
      "839869490635366400\n",
      "839804209770692608\n",
      "843110642910117888\n",
      "840570499422650368\n",
      "838157855663230976\n",
      "840886183490912256\n",
      "840879245080276992\n",
      "837680104363679744\n",
      "841344265740255232\n",
      "842735083944308736\n",
      "842735925179088896\n",
      "839875793512456192\n",
      "839859178712465408\n",
      "835436065190993920\n",
      "838163090607591424\n",
      "841289257443274752\n",
      "837679382431662080\n",
      "838159504024682496\n",
      "831457860721479680\n",
      "840984548597714944\n",
      "839864761947652096\n",
      "833702327444725760\n",
      "838388999964987392\n",
      "835139866269474816\n",
      "842740340824879104\n",
      "819509716299436032\n",
      "839869964864348160\n",
      "837682828706746368\n",
      "838405704879607808\n",
      "827151989283635200\n",
      "835125363007946752\n",
      "836344346444967936\n",
      "837373383242043392\n",
      "835136598269112320\n",
      "830380491126501376\n",
      "835121024906432512\n",
      "824618968198291456\n",
      "831104976066609152\n"
     ]
    },
    {
     "ename": "JSONDecodeError",
     "evalue": "Expecting value: line 1 column 1 (char 0)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mJSONDecodeError\u001b[0m                           Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-30-8324dc7c7798>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      7\u001b[0m         \u001b[0mlive_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0meach\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'live'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'id'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m      8\u001b[0m         \u001b[0mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mlive_id\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m         \u001b[0mget_audience\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlive_id\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-29-8a2c34e0d07e>\u001b[0m in \u001b[0;36mget_audience\u001b[0;34m(live_id)\u001b[0m\n\u001b[1;32m     19\u001b[0m         \u001b[0mr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrequests\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlink\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m=\u001b[0m \u001b[0mheaders\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m     20\u001b[0m         \u001b[0mhtml\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 21\u001b[0;31m         \u001b[0mdecodejson\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     22\u001b[0m         \u001b[0mdecodejson\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'live_id'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlive_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m     23\u001b[0m         \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlive_audience\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minsert_one\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdecodejson\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\json\\__init__.py\u001b[0m in \u001b[0;36mloads\u001b[0;34m(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001b[0m\n\u001b[1;32m    352\u001b[0m             \u001b[0mparse_int\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mparse_float\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    353\u001b[0m             parse_constant is None and object_pairs_hook is None and not kw):\n\u001b[0;32m--> 354\u001b[0;31m         \u001b[1;32mreturn\u001b[0m \u001b[0m_default_decoder\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    355\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mcls\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    356\u001b[0m         \u001b[0mcls\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mJSONDecoder\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mdecode\u001b[0;34m(self, s, _w)\u001b[0m\n\u001b[1;32m    337\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    338\u001b[0m         \"\"\"\n\u001b[0;32m--> 339\u001b[0;31m         \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mraw_decode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0midx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0m_w\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    340\u001b[0m         \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_w\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    341\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mC:\\ProgramData\\Anaconda3\\lib\\json\\decoder.py\u001b[0m in \u001b[0;36mraw_decode\u001b[0;34m(self, s, idx)\u001b[0m\n\u001b[1;32m    355\u001b[0m             \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mscan_once\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0midx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    356\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mStopIteration\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 357\u001b[0;31m             \u001b[1;32mraise\u001b[0m \u001b[0mJSONDecodeError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Expecting value\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ms\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    358\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mJSONDecodeError\u001b[0m: Expecting value: line 1 column 1 (char 0)"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "from pymongo import MongoClient\n",
    "import json\n",
    "import time\n",
    "import random\n",
    "\n",
    "client = MongoClient('localhost',27017)\n",
    "db = client.zhihu_database\n",
    "\n",
    "for each_page in db.live.find():\n",
    "    for each in each_page['data']:\n",
    "        live_id = each['live']['id']\n",
    "        print (live_id)        \n",
    "        get_audience(live_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
